<?php
class User extends AppModel {

	var $name = 'User';
	var $validate = array(
		'email' => array(
						'emil' => array(
										'rule' => 'email',
										'message' => 'Invalid e-mail addresss'
										),
						'uniq' => array('rule' => 'isUnique',
										'message' => 'This email is already registered'
										)
						),
		'pass' => array('notempty')
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Account' => array(
			'className' => 'Account',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Message' => array(
			'className' => 'Message',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

/*
 * set the user active to 1
 * 
*/
	function activate_user($id = null){
		if($id){
			$this->id = $id;
			$this->saveField('active', 1);
			return $id;
			}
		else
			return false;
	}
	
/*
 * Set the user as deleted
 * @param int $id the user id
*/
	function setDeleted($id = null){
		if($id){
			$this->id = $id;
			$this->saveField('active', -1);
			return $id;
		}
		else
			return false;
	}


}
?>